<?php
define("CLASSPATH","./classes/");

class ServiceListPrinter {

	private $soapClasses;
	
	public function __construct() {
	    $classes = array();
	    foreach( glob(CLASSPATH."*.class.php") as $fileName)
	    {
	        $className = substr($fileName,10,-10);
	        $classes[] = $className;
	        if(!file_exists(strtolower($className).".php")) {
		        $this->genClassPage($className);
	        }
	    }
	    $this->soapClasses = $classes;
	}
	
	private function genClassPage($className)
	{
	    $code = '';
	    $code .= '<?php
define("CLASSPATH","./classes/");
define("LIB","./lib/");
require_once(CLASSPATH."'.$className.'.class.php");
require_once(LIB."class.phpwsdl.php");
$soap=PhpWsdl::CreateInstance(
    null,								
    null,								
    "./cache",							
    Array(								
	    CLASSPATH."'.$className.'.class.php"
    ),
    null,								
    null,								
    null,								
    false,								
    true
);';
        file_put_contents(strtolower($className).".php",$code);        
	}
	
	public function show() {
	    $output = "";
	    $output .= "<html>";
	    $output .= "<head>";
	    $output .= "<title>OA WebServices</title>";
	    $output .= "<style>";
	    $output .= "body{font-family:Verdana,Calibri,Arial;background-color:#fefefe;}";
	    $output .= "a{text-decoration:none;}";
	    $output .= "a:hover{text-decoration:underline;}";
	    $output .= "</style>";
	    $output .= "</head>";
	    $output .= "<body>";
		$output .= "<h1>OA WebServices</h1>";
		if(sizeof($this->soapClasses)>0)
		{
		    $output .= "<ul>";
		    foreach ($this->soapClasses as $cls) {
			    $output .= "<li><h2><a href=\"".strtolower($cls).".php\">$cls</a></h2></li>";
		    }
		    $output .= "</ul>";
		    $output .= "<hr>";
		}
		$output .= "<p><small>Powered by <a href=\"http://www.tongda2000.com\">Tongda Tech.</a></small></p>";
		$output .= "</body>";
		$output .= "</html>";
		
		ob_end_clean();
		header('Content-Type: text/html');
		echo $output;
	}
}